﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Sword.Utility
{
    public static class StringUtility
    {
        const string IP_EXPRESS = @"[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}";
        const string DOMAIN_EXPRESS = @"((([a-zA-Z0-9_-]+\.){2}([a-zA-Z0-9_-]+))|(localhost)|(DST\d+))";
        public static bool IsIp4Address(string inputValue)
        {
            if (string.IsNullOrEmpty(inputValue)) return false;
            return Regex.IsMatch(inputValue, "^" + IP_EXPRESS + "$", RegexOptions.IgnoreCase);
        }

        public static bool IsOnlyDomain(string inputValue)
        {
            if (string.IsNullOrEmpty(inputValue)) return false;


            return Regex.IsMatch(inputValue, "^" + DOMAIN_EXPRESS + "$", RegexOptions.IgnoreCase);
        }
        public static bool IsUrl(string inputValue)
        {
            if (string.IsNullOrEmpty(inputValue)) return false;

            if (!Regex.IsMatch(inputValue, @"^(http[s]?\:\/\/)?" + IP_EXPRESS, RegexOptions.IgnoreCase) &&
                !Regex.IsMatch(inputValue, @"^(http[s]?\:\/\/)?" + DOMAIN_EXPRESS, RegexOptions.IgnoreCase))
            {
                return false;
            }

            return true;
        }
    }
}
